package com.sinosoft.bee.services.proposal.mapper;

import com.sinosoft.bee.services.proposal.entity.proposal.ProposalMain;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: TrickerL
 * @Description: bee
 * @Date: Create in 15:33 2018/5/16
 * @Modified By:
 */
@Mapper
@Repository
public interface ProposalMainMapper {
    /**
     * 向建议书主表新增建议书信息
     * @param proposalMain
     * @return
     */
    @Insert("INSERT INTO proposal_main (\n" +
            "  proposal_id,\n" +
            "  manage_com,\n" +
            "  agent_com,\n" +
            "  sale_channel,\n" +
            "  agent_code,\n" +
            "  agent_group,\n" +
            "  prem,\n" +
            "  amnt,\n" +
            "  STATUS,\n" +
            "  email,\n" +
            "  create_user,\n" +
            "  gmt_create,\n" +
            "  modified_user,\n" +
            "  gmt_modified,\n" +
            "  is_delete\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{proposalId},\n" +
            "    #{manageCom},\n" +
            "    #{agentCom},\n" +
            "    #{saleChannel},\n" +
            "    #{saleType},\n" +
            "    #{agentCode},\n" +
            "    #{agentGroup},\n" +
            "    #{prem},\n" +
            "    #{amnt},\n" +
            "    #{status},\n" +
            "    #{email},\n" +
            "    #{createUser},\n" +
            "    #{gmtCreate},\n" +
            "    #{modifiedUser},\n" +
            "    #{gmtModified},\n" +
            "    #{isDelete}\n" +
            "  );")
    Integer insertProposalMain(ProposalMain proposalMain);

    /**
     * 向主表插入除了保费，保额，用户邮箱的其他字段
     * @param proposalMain
     * @return
     */
    @Insert("INSERT INTO proposal_main (\n" +
            "  proposal_id,\n" +
            "  manage_com,\n" +
            "  agent_com,\n" +
            "  sale_channel,\n" +
            "  sale_type,\n" +
            "  agent_code,\n" +
            "  agent_group,\n" +
            "  status,\n" +
            "  create_user,\n" +
            "  gmt_create,\n" +
            "  modified_user,\n" +
            "  gmt_modified,\n" +
            "  is_delete\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{proposalId},\n" +
            "    #{manageCom},\n" +
            "    #{agentCom},\n" +
            "    #{saleChannel},\n" +
            "    #{saleType},\n" +
            "    #{agentCode},\n" +
            "    #{agentGroup},\n" +
            "    #{status},\n" +
            "    #{createUser},\n" +
            "    #{gmtCreate},\n" +
            "    #{modifiedUser},\n" +
            "    #{gmtModified},\n" +
            "    #{isDelete}\n" +
            "  );")
    Integer insertProposalMainPart(ProposalMain proposalMain);


    /**i
     * 删除建议书
     * @param proposalMain
     * @return
     */
    @Delete("delete from proposal_main where proposal_id=#{proposalId}")
    Integer deleteProposalMain(ProposalMain proposalMain);

    /**
     * 查询建议书
     * @return
     */
    @Results(id = "Main", value = {
            @Result(property = "proposalId", column = "proposal_id"),
            @Result(property = "manageCom", column = "manage_com"),
            @Result(property = "agentCom", column = "agent_com"),
            @Result(property = "saleChannel", column = "sale_channel"),
            @Result(property = "saleType", column = "sale_type"),
            @Result(property = "agentCode", column = "agent_code"),
            @Result(property = "agentGroup", column = "agent_group"),
            @Result(property = "prem", column = "prem"),
            @Result(property = "amnt", column = "amnt"),
            @Result(property = "status", column = "status"),
            @Result(property = "email", column = "email"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "gmtCreate", column = "gmt_create"),
            @Result(property = "modifiedUser", column = "modified_user"),
            @Result(property = "gmtModified", column = "gmt_modified"),
            @Result(property = "isDelete", column = "is_delete")
    })
    @Select("select * from proposal_main")
    List<ProposalMain> selectAllMain();

    /**
     * 修改建议书prem根据建议书号
     * @param main
     */
    @Update("update proposal_main set prem=#{prem} where proposal_id=#{proposalId};")
    void UpdateById(ProposalMain main);


}
